<style>
    /* 根据字数修改 pointsSupplierAccount*/
    .layui-form-label {
        width: 90px;
    }
</style>
<div class="layuimini-container layuimini-page-anim">
    <!-- 用于创建子页面 -->
    <div class="page-create"></div>
    <!-- page-main-create -->
    <!-- 用于显示 隐藏 -->
    <div class="layuimini-main page-main-create">
        <div class="title-row pb-0">
            <div class="title-left">
                <div class="title-info">
                    <div class="layui-tabs  noborder" id="planTabs">
                        <ul class="layui-tabs-header">
                            <li lay-id="1">评测报告</li>
                            <li lay-id="2">红黄绿灯一览表报告</li>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="title-right">
                <span class="account-table-btn layui-btn-primary" id="table-btn-0">
                    <button class="layui-btn layui-btn-sm" lay-on="download">批量导出</button>
                </span>
                <span class="account-table-btn layui-hide" id="table-btn-1">
                    <button class="layui-btn layui-btn-sm" lay-on="download">批量导出</button>
                </span>
            </div>
        </div>
        <hr class="m-0" />
        <div class="account-table section" id="table-0">
            <div class="m-df">
                <form class="layui-form" action="" lay-filter="search-form">
                    <div class="layui-form-item">
                        <div class="search-box-wrapper">
                            <div class="search-box-body">
                                <div class="layui-inline">
                                    <label class="layui-form-label">社区</label>
                                    <div class="layui-input-inline">
                                        <select class="layui-input" lay-append-to="body" placeholder="请选择"
                                            name="supplierCodes" lay-search>
                                            <option value="1">全部</option>
                                            <option value="2">市政道路</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">场所类型</label>
                                    <div class="layui-input-inline">
                                        <select class="layui-input" lay-append-to="body" placeholder="请选择"
                                            name="supplierCodes" lay-search>
                                            <option value="1">全部</option>
                                            <option value="2">路段</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">场所名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" placeholder="请输入" name="nickname" autocomplete="off"
                                            class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">测评人</label>
                                    <div class="layui-input-inline">
                                        <input type="text" placeholder="请输入" name="nickname" autocomplete="off"
                                            class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">亮灯结果</label>
                                    <div class="layui-input-inline">
                                        <select class="layui-input" lay-append-to="body" placeholder="请选择"
                                            name="supplierCodes" lay-search>
                                            <option value="1">全部</option>
                                            <option value="2">红灯</option>
                                            <option value="3">黄灯</option>
                                            <option value="4">绿灯</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">检查时间</label>
                                    <div class="layui-input-inline" style="width: 330px;">
                                        <input type="text" name="datePeriodStart" autocomplete="off"
                                            id="date_period_start" class="layui-input" placeholder="请选择">

                                    </div>
                                </div>




                            </div>
                            <div class="search-box-btns">
                                <div class="switch-wrapper" id="toggleFormBtn">
                                    <span>展开</span>
                                    <i class="layui-icon layui-icon-down" id="toggleIcon"></i>
                                </div>
                                <button type="submit" class="layui-btn layui-btn-sm" lay-submit
                                    lay-filter="data-search-btn">查询</button>
                                <button type="reset" class="layui-btn  layui-btn-sm layui-btn-primary">重置</button>

                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="font-weight mb-3">
                红灯：0
                黄灯：0
                绿灯：3
                无灯：0
            </div>
            <div class="table-stripe">
                <table class="layui-hide" id="accountTableId" lay-filter="accountTableFilter"></table>
            </div>
            <script type="text/html" id="accountTableBar">
                <a class="layui-font-blue mr-3" lay-event="detail">查看</a>
                <a class="layui-font-blue mr-3" lay-event="download">导出</a>
            </script>
        </div>
        <div class="account-table section layui-hide" id="table-1">
            <div class="m-df">
                <form class="layui-form" action="" lay-filter="search-form">
                    <div class="layui-form-item">
                        <div class="search-box-wrapper">
                            <div class="search-box-body">
                                <div class="layui-inline">
                                    <label class="layui-form-label">检查时间</label>
                                    <div class="layui-input-inline" style="width: 330px;">
                                        <input type="text" name="datePeriodStart" autocomplete="off"
                                            id="date_period_end" class="layui-input" placeholder="请选择">

                                    </div>
                                </div>

                            </div>
                            <div class="search-box-btns">
                                <button type="submit" class="layui-btn layui-btn-sm" lay-submit
                                    lay-filter="data-search-btn">查询</button>
                                <button type="reset" class="layui-btn  layui-btn-sm layui-btn-primary">重置</button>

                            </div>
                        </div>
                    </div>
                </form>
            </div>


            <div class="table-stripe">
                <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
            </div>
            <script type="text/html" id="currentTableBar">
                <a class="layui-font-blue mr-3" lay-event="download">导出</a>
            </script>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table', 'tabs', 'miniPage', 'element'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            tabs = layui.tabs,
            laydate = layui.laydate,
            layer = layui.layer,
            util = layui.util,
            element = layui.element,
            miniPage = layui.miniPage;
        /******************** 事件 start ********************/

        /******************** 事件 end ********************/

        util.on('lay-on', {
            'download': function () {


            },
            'download': function () {
            }
        })



        /******************** 渲染组件 start ********************/
        form.render('select'); //刷新select选择框渲染
        // 起始日期
        laydate.render({
            elem: '#date_period_start',
            type: 'datetime',
            range: true
        });
        // 截止日期
        laydate.render({
            elem: '#date_period_end',
            type: 'datetime',
            range: true
        });
        // 初始化选项卡
        tabs.render({
            elem: '#planTabs',
            index: 0// 默认选中
        });




        // 初始化选项卡
        tabs.render({
            elem: '#planTabs',
            index: 0// 默认选中
        });
        // tabs 切换后的事件
        function handleTabSwitch(tabIndex) {
            $('.account-table').addClass('layui-hide');
            // 显示当前 tab 对应的 work-section
            $('#table-' + tabIndex).removeClass('layui-hide');


            $('.account-table-btn').addClass('layui-hide');

            $('#table-btn-' + tabIndex).removeClass('layui-hide');

        }

        // planTabs 切换事件
        tabs.on('afterChange(planTabs)', function (data) {
            var tabIndex = data.index;
            handleTabSwitch(tabIndex); // 调用处理函数
        });

        // 页面加载完成后默认执行一次
        $(document).ready(function () {
            handleTabSwitch(0);
        });






        /******************** 渲染组件 end ********************/
        table.render({
            elem: '#accountTableId',
            url: 'api/table.json',
            cols: [[

                { type: 'numbers', width: 80, title: '序号' },
                { field: 'name', minWidth: 110, title: '公司名称' },
                { field: 'name', minWidth: 120, title: '场所类型' },
                { field: 'name', minWidth: 120, title: '社区' },
                { field: 'name', minWidth: 120, title: '报告' },
                { field: 'name', minWidth: 180, title: '检查时间' },
                { field: 'name', minWidth: 180, title: '场所名称' },
                { field: 'name', minWidth: 180, title: '测评人' },
                { field: 'name', minWidth: 180, title: '得分' },
                { field: 'name', minWidth: 180, title: '亮灯结果' },
                { title: '操作', width: 140, toolbar: '#accountTableBar', align: "center", fixed: 'right' }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
            size: 'lg'
        });

        table.on('tool(accountTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                var content = miniPage.getHrefContent('page/table/add.html');
                var openWH = miniPage.getOpenWidthHeight();

                var index = layer.open({
                    title: '编辑用户',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'dowload') {
                console.log('导出---')
            }
        });


        table.render({
            elem: '#currentTableId',
            url: 'api/table.json',
            cols: [[
                { type: 'numbers', width: 80, title: '序号' },
                { field: 'name',minWidth: 180, title: '报告' },
                { title: '操作', width: 100, toolbar: '#currentTableBar', align: "center", fixed: 'right' }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
            size: 'lg'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar事件监听
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'download') {  // 监听删除操作

            }
        });



        // 开启监听 折叠展开事件
        miniPage.listen()

    });
</script>